package com.itrus.manager;

import com.itrus.mapper.WalletMapper;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;

@Component
public class WalletAdd2Manager {

    @Resource
    private WalletMapper walletMapper;

    @Transactional(propagation = Propagation.REQUIRED)
    public void addById2(boolean throwException){
        walletMapper.addBalance(2L,1);
        if (throwException){
            throw new RuntimeException("222222");
        }
    }
    @Transactional(propagation = Propagation.NESTED)
    public void addById2_nested(boolean throwException) {
        walletMapper.addBalance(2L,1);
        if (throwException){
            int a = 1/0;
        }
    }
    @Transactional(propagation = Propagation.REQUIRES_NEW)
    public void addById2_new(boolean throwException){
        walletMapper.addBalance(2L,1);
        if (throwException){
            throw new RuntimeException("222222");
        }
    }

    public void addById2_no(boolean throwException){
        walletMapper.addBalance(2L,1);
        if (throwException){
            throw new RuntimeException("222222");
        }
    }
}
